import 'package:dashboard/dio/dio_gateway.dart';
import 'package:flutter/material.dart';

class Header extends StatefulWidget {
  const Header({super.key, required this.onPathChanged});
  final ValueChanged<String> onPathChanged;
  @override
  State<Header> createState() => _HeaderState();
}

class _HeaderState extends State<Header> {
  late Map<String, dynamic> data = {};

  loadAsync() async {
    data = await GateWayDio.GetStatistical();
  }

  @override
  Widget build(BuildContext context) {
    return FutureBuilder(
      future: loadAsync(),
      builder: (context, snapshot) {
        return Container(
            height: 40,
            decoration: const BoxDecoration(
              color: Color(0xff272727),
              borderRadius: BorderRadius.only(
                topLeft: Radius.circular(5),
                topRight: Radius.circular(5),
              ),
            ),
            padding: const EdgeInsets.only(left: 10, right: 10),
            child: Row(
              children: [
                Badge(
                  label: Text("${data['cluster'] ?? 0}"),
                  backgroundColor: Colors.blue,
                  child: ElevatedButton.icon(
                      onPressed: () {
                        widget.onPathChanged('集群状态');
                      },
                      icon: const Icon(Icons.leaderboard),
                      label: const Text('集群状态'),
                      style: ElevatedButton.styleFrom(
                        primary: Colors.transparent,
                      )),
                ),
                const SizedBox(
                  width: 20,
                ),
                // Badge(
                //   label: Text("${data['conn'] ?? 0}"),
                //   backgroundColor: Colors.blue,
                //   child: ElevatedButton.icon(
                //       onPressed: () {
                //         widget.onPathChanged('在线连接');
                //       },
                //       icon: const Icon(Icons.menu),
                //       label: const Text('在线连接'),
                //       style: ElevatedButton.styleFrom(
                //         primary: Colors.transparent,
                //       )),
                // ),
                // const SizedBox(
                //   width: 20,
                // ),
                Badge(
                  label: Text("${data['channel'] ?? 0}"),
                  backgroundColor: Colors.blue,
                  child: ElevatedButton.icon(
                      onPressed: () {
                        widget.onPathChanged('频道');
                      },
                      icon: const Icon(Icons.menu),
                      label: const Text('频道'),
                      style: ElevatedButton.styleFrom(
                        primary: Colors.transparent,
                      )),
                ),
                const SizedBox(
                  width: 20,
                ),
                ElevatedButton.icon(
                    onPressed: () {
                      widget.onPathChanged('操作');
                    },
                    icon: const Icon(Icons.edit_square),
                    label: const Text('操作'),
                    style: ElevatedButton.styleFrom(
                      primary: Colors.transparent,
                    )),
                const Spacer(),
                ElevatedButton(
                    onPressed: () {},
                    style: ElevatedButton.styleFrom(
                      primary: Colors.transparent,
                    ),
                    child: const Icon(Icons.account_circle)),
              ],
            ));
      },
    );
  }
}
